
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
	<form action="test.php" method="post">
		<input type="text" name="id"><br> <br> <input type="submit"
			value="ค้นหา"><br> <br>
	</form>

	<?php

	class Subjects{
		private $subjectId;
		private $subjectName;
		private $unit;


		public function __construct($subjectId,$subjectName,$unit){
			$this->subjectId = $subjectId;
			$this->subjectName = $subjectName;
			$this->unit = $unit;
		}

		public function getSubjectId(){
			return $this->subjectId;
		}
		public function getSubjectName(){
			return $this->subjectName;
		}
		public function getUnit(){
			return $this->unit;
		}
	}
	class Students{
		private $studentId;
		private $studentName;
		private $degrees;
		private $address;

		public function __construct($studentId,$studentName,$degrees,$address){
			$this->studentId = $studentId;
			$this->studentName = $studentName;
			$this->degrees = $degrees;
			$this->address = $address;
		}

		public function getStudentId(){
			return $this->studentId;
		}
		public function getStudentName(){
			return $this->studentName;
		}
		public function getDegrees(){
			return $this->degrees;
		}
		public function getAddress(){
			return $this->address;
		}
	}
	class Registers{
		private $subject;
		private $students;
		private $score;
		private $strGrade;

		public function __construct($subject,$students,$score){
			$this->subject = $subject;
			$this->students = $students;
			$this->score = $score;
		}


		public function getSubject(){
			return $this->subject;
		}

		public function getStudent(){
			return $this->students;
		}

		public function getScore(){
			return $this->score;
		}
		public function checkData(){
			if($this->score == "W"){
				$this->strGrade = "W";
			}
			else if($this->score == "I"){
				$this->strGrade = "I";
			}
			else if($this->degrees == "ป.ตรี"){
				if($this->score >= 80){
					$this->strGrade = "A";
				}
				else if($this->score >= 70 && $this->score < 80){
					$this->strGrade = "B";
				}
				else if($this->score >= 60 && $this->score < 70 ){
					$this->strGrade = "C";
				}
				else if($this->score >= 50 && $this->score < 60){
					$this->strGrade = "D";
				}
				else {
					$this->strGradde = "F";
				}

			}
			else {

				if($this->score >= 80 ){
					$this->strGrade = "A";
				}
				else if($this->score >= 70 && $this->score < 80){
					$this->strGrade = "B";
				}
				else{
					$this->strGrade = "C";
				}
			}
			return $this->strGrade;
		}

		public function checkGrade(){
			if($this->strGrade == "A"){
				$this->intGrade = 4;
			}
			else if($this->strGrade == "B"){
				$this->intGrade = 3;
			}
			else if($this->strGrade == "C"){
				$this->intGrade = 2;
			}
			else if($this->strGrade == "D"){
				$this->intGrade = 1;
			}
			else{
				$this->intGrade = 0;
			}
			return $this->intGrade;
		}
	}
	$subjects[]= new Subjects("ทส101","การออกแบบกราฟิก",3);
	$subjects[]= new Subjects("ทส201","การออกแบบฐานข้ อมูลเบื้องต้น",3);
	$subjects[]= new Subjects("ทส301","การเขียนโปรแกรมชั้นสูง",1);

	$studentes[] = new Students("5304106305","นางสาวกฤตยาณี  พันธุ์อุทิศพงศ","ป.โท","สาขาวิชาเทคโนโลยีสารสนเทศ,สาขา A,สาขา B");
	$studentes[] = new Students("5304106307","นางสาวกิตติยา ดาวทอง ","ป.ตรี","สาขาวิชาเทคโนโลยีสารสนเทศ");
	$studentes[] = new Students("5304106308","นางสาวจันทร์หอม แสนประเสริฐสรรค","ป.โท","สาขาวิชาเทคโนโลยีสารสนเทศ,สาขา A,สาขา B");
	$studentes[] = new Students("5304106309","นายจิตรกร ศรีคำมูล ","ป.ตรี","สาขาวิชาเทคโนโลยีสารสนเทศ");
	$studentes[] = new Students("5304106311","นายฉัฐวัสส์ ครองยุทธ","ป.โท","สาขาวิชาเทคโนโลยีสารสนเทศ");
	$studentes[] = new Students("5304106312","นายฉัตรรพี ใจอุดม","ป.ตรี","สาขาวิชาเทคโนโลยีสารสนเทศ,สาขา A,สาขา B");
	$studentes[] = new Students("5304106313","นายชัยสุวรรณ อนุการ","ป.โท","สาขาวิชาเทคโนโลยีสารสนเทศ");
	$studentes[] = new Students("5304106314","นายณัฐ คงรอด","ป.ตรี","สาขาวิชาเทคโนโลยีสารสนเทศ");
	$studentes[] = new Students("5304106316","นายธเนศ เขื่อนล้อม","ป.โท","สาขาวิชาเทคโนโลยีสารสนเทศ");
	$studentes[] = new Students("5304106317","นายธีรพงศ์ อิทธิเสรีกุล","ป.ตรี","สาขาวิชาเทคโนโลยีสารสนเทศ,สาขา A,สาขา B");

	$registers[] = new Registers($subjects[0],$studentes[0],60);
	$registers[] = new Registers($subjects[0],$studentes[1],70);
	$registers[] = new Registers($subjects[0],$studentes[2],80);
	$registers[] = new Registers($subjects[0],$studentes[3],46);
	$registers[] = new Registers($subjects[0],$studentes[4],W);
	$registers[] = new Registers($subjects[0],$studentes[5],13);
	$registers[] = new Registers($subjects[0],$studentes[6],60);
	$registers[] = new Registers($subjects[0],$studentes[7],I);
	$registers[] = new Registers($subjects[0],$studentes[8],80);
	$registers[] = new Registers($subjects[0],$studentes[9],90);

	$registers[] = new Registers($subjects[1],$studentes[0],42);
	$registers[] = new Registers($subjects[1],$studentes[1],62);
	$registers[] = new Registers($subjects[1],$studentes[2],72);
	$registers[] = new Registers($subjects[1],$studentes[3],I);
	$registers[] = new Registers($subjects[1],$studentes[4],69);
	$registers[] = new Registers($subjects[1],$studentes[5],45);
	$registers[] = new Registers($subjects[1],$studentes[6],25);
	$registers[] = new Registers($subjects[1],$studentes[7],87);
	$registers[] = new Registers($subjects[1],$studentes[8],45);
	$registers[] = new Registers($subjects[1],$studentes[9],65);

	$registers[] = new Registers($subjects[2],$studentes[0],85);
	$registers[] = new Registers($subjects[2],$studentes[1],64);
	$registers[] = new Registers($subjects[2],$studentes[2],85);
	$registers[] = new Registers($subjects[2],$studentes[3],45);
	$registers[] = new Registers($subjects[2],$studentes[4],30);
	$registers[] = new Registers($subjects[2],$studentes[5],W);
	$registers[] = new Registers($subjects[2],$studentes[6],62);
	$registers[] = new Registers($subjects[2],$studentes[7],75);
	$registers[] = new Registers($subjects[2],$studentes[8],12);
	$registers[] = new Registers($subjects[2],$studentes[9],85);

	$stuId = $_POST['id'];

	if(isset($_POST['id'])){

		$index=1;
		
		
		$counts =0 ;
		$sum = 0;
		for($i=0;$i<count($registers);$i++){
			if($stuId == $registers[$i]->getStudent()->getStudentId()){
				echo "&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp
			ใบรายงานผลการเรียน <br>";
				echo "รหัสนักศึกษา".$_POST['id']."&nbsp&nbsp ชื่อ  &nbsp".$registers[$i]->getStudent()->getStudentName()."<br>";
				echo "&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbspหลักสูตรมหาบัณฑิต (".$registers[$i]->getStudent()->getDegrees()." )<br><br>";
				echo "ที่อยู่ที่ 1 :".$registers[$i]->getStudent()->getAddress()."<br><br>";
				echo "ระเบียนผลการเรียน ภาคการเรียนที่ 2 ปีการศึกษา 2554<br><br>";
				echo "-------------------------------------------------------------------------------------------------------------<br>";
				echo "ลำดับ &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp รหัสวิชา&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp
				ชื่อวิ ชา   &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp ผลการเรียน <br><br>";
				echo "-------------------------------------------------------------------------------------------------------------<br>";
				break;	
			}
		}
		for($j=0;$j<count($registers);$j++){
			if($stuId == $registers[$j]->getStudent()->getStudentId()){
		echo " ".($index++)."&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp".$registers[$j]->getSubject()->getSubjectId().
		"&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp".$registers[$j]->getSubject()->getSubjectName()."&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp
				&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp".$registers[$j]->checkData()."<br><br>";
		
		$counts += $registers[$j]->getSubject()->getUnit();
		$sum +=  $registers[$j]->getSubject()->getUnit() *$registers[$j]->checkGrade();
			}
		}
		echo "-------------------------------------------------------------------------------------------------------------<br>";
		echo  "หน่วยกิตรวม&nbsp&nbsp&nbsp ".number_format($counts,2)."&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp";
		echo  " GPA &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp".number_format (($sum/$counts),2);
	}
	?>

</body>
</html>

